********************************************************************************
** 	TITLE: f11_sag_gen_diffindiff.do

**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Table XI: County Difference-in-Differences Estimates
********************************************************************************
**  PURPOSE: Genesee and Saginaw Diff-in-Diff
********************************************************************************
set sortseed 13
	
	use "$output_data/estimate.dta", replace
	est clear
	
	append using "$output_data/sag_post_roa_all.dta"

	keep inmate booking_date release_date genesee e_sample stay_rec ignite_0_rec
	
	tempfile basesaggen
	
	save `basesaggen', replace
	
use "$output_data/sag_gen_appended.dta", clear

merge 1:1 inmate booking_date release_date genesee using `basesaggen', keep(3) ///
keepusing(e_sample stay_rec ignite_0_rec) assert(1 3) nogen	

				//stay ignite_0 for Recidivism
				gen stay = stay_rec
				gen ignite_0 = ignite_0_rec				

/*********************************************************************************
//Recidivism Measured in Each County
**********************************************************************************/	
* diff-in-diff
	* full estimate sample
		su return_3m if genesee&!D_ignite_proxy&return_3m>=0
		local mean: di %8.3f r(mean)		

* col 1
		qui reg return_3m  i.month i.year  ///
				D_ignite_proxy##genesee if return_3m>=0&(genesee|(!genesee&e_sample)), ///
				cluster(inmate)
	
		eststo col1
		estadd local raw_mean `mean': col1
		estadd local ind_cahr "No": col1
	
* col 2
		qui reg return_3m  i.month  i.year (D_female D_Black age_25_34 age_35_44 ///
			age_45_54 age_55_64 age_17_24 prior_offense_1y)##D_ignite_proxy ///
				D_ignite_proxy##genesee if return_3m>=0&(genesee|(!genesee&e_sample)), ///
				cluster(inmate)
		eststo col2
		estadd local raw_mean `mean': col2
		estadd local ind_cahr "Yes": col2

capture drop return_*m prior_offense_1y
merge 1:1 inmate booking_date release_date genesee using "$output_data/sag_gen_updated.dta", ///
keep(3) keepusing(sg_id return_*m sum_genesee sum_saginaw prior_offense_1y) assert(2 3) nogen

unique sg_id if sum_genesee&sum_saginaw

/*********************************************************************************
//Recidivism Measured in Both Counties
**********************************************************************************/	
* diff-in-diff
	* full estimate sample
		su return_3m if genesee&!D_ignite_proxy&return_3m>=0
		local mean: di %8.3f r(mean)
	
* col 3
		reg return_3m  i.month  i.year  ///
				D_ignite_proxy##genesee  if return_3m>=0&(genesee|(!genesee&e_sample)), ///
				cluster(inmate)
		eststo col3
		estadd local raw_mean `mean': col3
		estadd local ind_cahr "Yes": col3
	
* col 4
		reg return_3m  i.month  i.year (D_female D_Black age_25_34 age_35_44 ///
			age_45_54 age_55_64 age_17_24 prior_offense_1y)##D_ignite_proxy ///
				D_ignite_proxy##genesee  if return_3m>=0&(genesee|(!genesee&e_sample)), ///
				cluster(inmate)
		eststo col4
		estadd local raw_mean `mean': col4
		estadd local ind_cahr "Yes": col4
	
	
		estout col1 col2 col3 col4 using "$tables/sag_gen_did_updated.tex",  replace ///
			style(tex) nolabel ///
			collabels(none) cells(b(star fmt(%8.3f)) se(par fmt(%8.3f)))  starlevels(* 0.10 ** 0.05 *** 0.01)  ///
			mlabels(none) /// 
			keep(1.D_ignite_proxy#1.genesee 1.genesee 1.D_ignite_proxy ) ///
			order(1.D_ignite_proxy#1.genesee 1.genesee 1.D_ignite_proxy) ///
			varlabel(1.D_ignite_proxy#1.genesee "Post $ \times $ Genesee" ///
				1.genesee "Genesee"  ///
				1.D_ignite_proxy "Post") ///
			nobaselevels  ///
			label ///
			stats(foo raw_mean ind_cahr N , fmt(0 %8.3f 0 %8.0gc) /// 			
			labels(" " "Control Mean"  "Ind. Chars. $\times$ Post " "Observations" )) ///
			prehead(%) posthead(%) postfoot(%) 